﻿singleApp.controller('change_parentCtrl', ['$http', '$scope', function ($http, $scope) {
    $scope.model = {
        id: window.singleConfig.id,
        phone: ""
    };

    $scope.confirm = function () {

        if ($scope.model.phone == "") {
            layer.msg("手机号不能为空！");
            return;
        }

        var api_url = window.singleConfig.rootUrl + 'api/admin/UsersService/change_parent';
        layer.load(2);
        $http({
            method: 'POST',
            url: api_url,
            data: $.param($scope.model),
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
        .then(function (result) {
            var data = result.data;
            if (data.code == "success") {
                layer.closeAll();
                layer.msg("更新成功！");
            }
            else {
                layer.closeAll();
                layer.msg(data.message);
            }
        }, function (data) {
            layer.msg("系统错误!");
        });

    };

    $scope.search = function () {
        if ($scope.model.phone == "") {
            layer.msg("手机号不能为空！");
            return;
        }

        layer.load(2);
        var api_url = window.singleConfig.rootUrl + "api/admin/UsersService/get_user_by_phone?phone=" + $scope.model.phone;

        $http.get(api_url).then(function (result) {
            var data = result.data;
            //layer.msg(data.message);
            layer.closeAll();
            angular.element("#spanFindUserName").html(data.message);
        }, function () { });
    };
}]);